package com.hiro.framework.tilegame.controller;

import com.hiro.framework.tilegame.controller.system.STileGameSystem;
import com.hiro.framework.tilegame.model.actor.ITileBoard;


public class GameStartState extends GameState {
    private static GameStartState instance;
    private static byte[] lock = new byte[0];

//    private FifteenPuzzleCanvas canvas;
//    private ItileBoard tileBoard;

//    private GameStartState(FifteenPuzzleCanvas canvas, ItileBoard tileBoard) {
//        this.canvas = canvas;
//        this.tileBoard = tileBoard;
//    }
    
    private GameStartState(ITileBoard tileBoard) {
        super(tileBoard);
    }

    public static GameStartState getInstance(ITileBoard tileBoard) {
        if (instance == null || instance.equals(tileBoard) == false) {
            synchronized (lock) {
                if (instance == null || instance.equals(tileBoard) == false) {
                    instance = new GameStartState(tileBoard);
                }
            }
        }
        return instance;
    }
    
    public void startGame(){
        tileBoard.initailize();
        restartGame();
    }

    public void restartGame(){
        tileBoard.reset();
        STileGameSystem.getInstance().refreshView();
        STileGameSystem.getInstance().setState(WaitingForKeyState.getInstance(tileBoard));
    }
}
